package com.example.cunwan_hd.Server;

import com.alibaba.fastjson.JSONObject;
import com.example.cunwan_hd.Mapper.DataMapper;
import com.example.cunwan_hd.Pojo.Requstet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Map;

@Service
public class Chatservice {
    @Autowired DataMapper dataMapper ;

    public  boolean chat(String data){




        JSONObject json =JSONObject.parseObject(data);
        String content= json.getString("content");
        String url ="https://api.wordscheck.com/check";
        RestTemplate rest =new RestTemplate();
        Requstet r= new Requstet();
        r.setKey("aQprzN0lqqxQeW67Qg6qHBUnfJ7W4C6N");
        r.setContent(content);
        HttpEntity<Requstet> pp =new HttpEntity<>(r);
        Map  out =rest.postForObject(url,pp,Map.class);
        List list =(List) out.get("word_list");
        System.out.println(list.size());
        if (list.size()==0){
            dataMapper.in(data);


            return true;
        }else {
            return false;
        }


    }

}
